package com.baizhi.service.impl;

import com.baizhi.annotation.LogAnnotation;
import com.baizhi.dao.GuruDao;
import com.baizhi.entity.Guru;
import com.baizhi.service.GuruService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 野马 on 2019/6/17.
 */
@Service
public class GuruServiceImpl implements GuruService {

    private Logger logger = LoggerFactory.getLogger(GuruServiceImpl.class);


    @Autowired
    private GuruDao guruDao;

    @Override
    @LogAnnotation(value = "执行了上师操作")
    public Map selectGuru(String guruName, int page, int rows) {
        //从第几条开始
        int start = (page-1)*rows;
        //每天几条数据
        int pageSize = rows;
        //模糊查询
        if(guruName != null && !"".equals(guruName)){
            guruName = "%"+guruName+"%";
        }else {
            guruName = null;
        }

        int countGuru = guruDao.countGuru(guruName);
        List<Guru> guruList = guruDao.selectGuru(guruName, start, pageSize);

        Map map = new HashMap();
        map.put("total",countGuru);
        map.put("rows",guruList);


        return map;
    }

    @Override
    public void insertGuru(Guru guru) {
        logger.debug("开始执行查询方法degug");
        logger.info("开始执行查询方法info");
        logger.warn("开始执行查询方法warn");
        logger.error("开始执行查询方法error");
        guruDao.insertGuru(guru);
    }

    @Override
    public void freezeGuru() {

    }

    @Override
    public List<Guru> selectList() {
        List<Guru> guruList = guruDao.selectList();
        logger.info(""+guruList+"字符串拼接");
        logger.info("{}",guruList+"占位符");
        return guruList;
    }
}
